/*
 
 File: matrix.h
 
 Abstract: simple 4x4 matrix computations
 
 Version: 1.0
 
 Disclaimer: IMPORTANT:  This Apple software is supplied to you by Apple Inc.
 ("Apple") in consideration of your agreement to the following terms, and your
 use, installation, modification or redistribution of this Apple software
 constitutes acceptance of these terms.  If you do not agree with these terms,
 please do not use, install, modify or redistribute this Apple software.
 
 In consideration of your agreement to abide by the following terms, and subject
 to these terms, Apple grants you a personal, non-exclusive license, under
 Apple's copyrights in this original Apple software (the "Apple Software"), to
 use, reproduce, modify and redistribute the Apple Software, with or without
 modifications, in source and/or binary forms; provided that if you redistribute
 the Apple Software in its entirety and without modifications, you must retain
 this notice and the following text and disclaimers in all such redistributions
 of the Apple Software.
 Neither the name, trademarks, service marks or logos of Apple Inc. may be used
 to endorse or promote products derived from the Apple Software without specific
 prior written permission from Apple.  Except as expressly stated in this notice,
 no other rights or licenses, express or implied, are granted by Apple herein,
 including but not limited to any patent rights that may be infringed by your
 derivative works or by other works in which the Apple Software may be
 incorporated.
 
 The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO
 WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
 WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
 COMBINATION WITH YOUR PRODUCTS.
 
 IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR
 DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF
 CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
 APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 Copyright (C) 2009 Apple Inc. All Rights Reserved.
 
*/



#import <UIKit/UIKit.h>

#ifdef __cplusplus
extern "C" {
#endif
	/**
	 * \defgroup Matrix Matrix
	 */
	/*@{*/	
	
	// Apple functions
	/**
	 * Makes m to an identity matrix
	 @param m Pointer to an float array which becomes the identity matrix
	 @remark All matrix functions uses 16 units large float arrays as input!
	 **/
	void mat4f_LoadIdentity(float* m);
	
	/**
	 * Makes m to an Orthogonal projection matrix
	 @param left  left clipping plane
	 @param right right clipping plane
	 @param bottom bottom clipping plane
	 @param top top clipping plane
	 @param near near clipping plane
	 @param far far clipping plane
	 @param mout Pointer to an float array which becomes the projection matrix
	 @remark All matrix functions uses 16 units large float arrays as input!
	 **/
	void mat4f_LoadOrtho(float left, float right, float bottom, float top, float near, float far, float* mout);

	// Void Dead extensions
	//\cond
	void mat4f_LoadProjectionX(float* m, float *modelMatrix);
	//\endcond
	
	/**
	 * Creates an Orthogonal projection matrix with an rotated model matrix. (The rotation depends on the device orientation)
	 @param m Pointer to an float array which becomes the new matrix
	 @remark All matrix functions uses 16 units large float arrays as input!
	 **/
	void mat4f_LoadProjection(float* m);
	
	//\cond
	void mat4f_LoadProjectionWithoutRotationX(float* m, float *modelMatrix);
	//\endcond
	
	/**
	 * Creates an Orthogonal projection matrix with an unrotated model matrix.
	 @param m Pointer to an float array which becomes the new matrix
	 @remark All matrix functions uses 16 units large float arrays as input!
	 **/
	void mat4f_LoadProjectionWithoutRotation(float* m);

	/**
	 * Multiplies matrix sA with sB and stores the result in mout
	 @param sA Matrix A
	 @param sB Matrix B
	 @param mout The matrix which becomes the result from A * B
	 @remark All matrix functions uses 16 units large float arrays as input!
	 **/
	void mat4f_MultiplyMat4f(float* mout, float *sA, float *sB);

	/**
	 * Translates the given matrix in the given directions
	 @param mout The matrix which should be translated
	 @param tx Translation on the X axis
	 @param ty Translation on the Y axis
	 @param tz Translation on the Z axis
	 @remark All matrix functions uses 16 units large float arrays as input!
	 **/
	void mat4f_translate(float *mout, float tx, float ty, float tz);
	
	/**
	 * Rotates the given matrix in the given angle.
	 @param mout The matrix which should be rotated
	 @param angle The rotation angle in degrees
	 @param x Rotation on the X axis
	 @param y Rotation on the Y axis
	 @param z Rotation on the Z axis
	 @remark All matrix functions uses 16 units large float arrays as input!
	 **/
	void mat4f_rotate(float *mout, float angle, float x, float y, float z);
	
	/**
	 * Rotates the given matrix in the given angle but with respect to the device orientation.
	 @param mout The matrix which should be rotated
	 @param angle The rotation angle in degrees
	 @param x Rotation on the X axis
	 @param y Rotation on the Y axis
	 @param z Rotation on the Z axis
	 @remark All matrix functions uses 16 units large float arrays as input!
	 */
	void mat4f_rotateIndependent(float *mout, float angle, float x, float y, float z);
	
	/**
	 * Rotates the given matrix to the device orientation.
	 @param m The matrix which should be rotated
	 @param es1Only If this is set to YES, the matrix will be only rotated when the engine uses OpenGL ES 1.1 (usefull when you use render to texture)
	 @remark All matrix functions uses 16 units large float arrays as input!
	 **/
	void mat4f_moveForOrientation(float *m, BOOL es1Only);
	

	/*@}*/
	
#ifdef __cplusplus
}
#endif	
